package com.heima.wemedia.controller.v1;

import com.heima.model.common.constants.wemedia.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDTO;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Api(tags = "文件管理")
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Autowired
    WmMaterialService wmMaterialService;

    //文件上传
    @ApiOperation("文件上传")
    @PostMapping("/upload_picture")
    public ResponseResult uploadFile(MultipartFile multipartFile){
        return wmMaterialService.uploadImages(multipartFile);
    }
    //查询文件列表信息
    @ApiOperation("查询文件列表信息")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDTO wmMaterialDTO){
        return wmMaterialService.findList(wmMaterialDTO);
    }
    //文件删除
    @ApiOperation(value = "删除素材",notes = "根据ID删除素材,有关联的素材不可以删除")
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable("id") Integer id) {
        return wmMaterialService.deleteImage(id);
    }
    /*
    * 图片收藏
    * */
    @ApiOperation("收藏素材")
    @GetMapping("/collect/{id}")
    public ResponseResult collectionMaterial(@PathVariable("id") Integer id) {
        return wmMaterialService.updateStatus(id, WemediaConstants.COLLECT_MATERIAL);
    }
    /*
    * 取消收藏
    * */
    @ApiOperation("取消收藏素材")
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollectionMaterial(@PathVariable("id") Integer id) {
        return wmMaterialService.updateStatus(id, WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }
}
